package yl.hs.bmipfull.controllers.laboratory;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yl.hs.bmipfull.controllers.ControllerBase;
import yl.hs.bmipfull.service.laboratory.IProductConfigService;
import yl.hs.bmipfull.service.laboratory.ITaskConfigService;
import yl.hs.bmipfull.viewmodels.SubmitModel;
import yl.hs.bmipfull.viewmodels.WebResult;

/**
 * TaskCofigController
 *
 * @author 谢景广
 * @category
 * @date 2021-06-09
 */
@Api(value = "生产任务配比", tags = "实验室管理——生产任务配比")
@RequestMapping(value = "/api/production/")
@RestController
public class TaskConfigController extends ControllerBase {

    @Autowired
    ITaskConfigService taskConfigSvc;
    @Autowired
    IProductConfigService configService;
    @ApiOperation(value = "根据生产任务编号获取生产任务的配比详情", notes = "查询产品信息表")
    @RequestMapping(path = "/taskConfig/{taskSN}", method = RequestMethod.GET)
    public WebResult queryConfigByTaskSN(@ApiParam("生产任务编号") @PathVariable String taskSN) {
        try {
            var result = taskConfigSvc.queryConfigByTaskSN(taskSN);
            return success("ok", result);
        } catch (Exception ex) {
            return error(ex);
        }
    }
    @ApiOperation(value = "根据生产任务编号获取生产任务的配比信息", notes = "查询配比信息")
    @RequestMapping(path = "/productconfig/{taskSN}", method = RequestMethod.GET)
    public WebResult queryByTaskSN(@ApiParam("生产任务编号") @PathVariable String taskSN) {
        try {
            var taskconfig = taskConfigSvc.queryConfigEntityByTaskSN(taskSN);
            if(taskconfig!=null && taskconfig.size()>0){
                var config = configService.findBySn(taskconfig.get(0).getConfigSN());
                return success("ok", config);
            }else{
                return success("未找到数据", null);
            }
        } catch (Exception ex) {
            return error(ex);
        }
    }
    @ApiOperation(value = "根据生产任务编号获取生产任务的配比详情", notes = "查询产品信息表")
    @RequestMapping(path = "/saveConfig", method = RequestMethod.POST)
    public WebResult saveTaskConfig(@ApiParam("生产任务编号") @RequestBody SubmitModel model) {
        try {
            Integer result = taskConfigSvc.saveConfig(model);


            return success("ok", "");
        } catch (Exception ex) {
            return error(ex);
        }
    }
    @ApiOperation(value = "根据生产任务编号获取生产任务的配比详情", notes = "查询产品信息表")
    @RequestMapping(path = "/hfsaveConfig", method = RequestMethod.POST)
    public WebResult saveHfTaskConfig(@ApiParam("生产任务编号") @RequestBody SubmitModel model) {
        try {
            Integer result = taskConfigSvc.HfsaveConfig(model);


            return success("ok", "");
        } catch (Exception ex) {
            return error(ex);
        }
    }
}
